package main

import (
	"fmt"
	_ "gfweb/boot"
	"gfweb/cachetest"
	"gfweb/datavalidation"
	"gfweb/errtest"
	"gfweb/logtest"
	_ "gfweb/router"
	"gfweb/tracetest"
	"gfweb/typeconvertest"
	"github.com/gogf/gf/database/gredis"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/os/gcron"
	"time"
)

var itime int

func test_err() {
	errtest.Errtest.Error1()
	errtest.Errtest.Error2()
	errtest.Errtest.Error3()
	errtest.Errtest.Error4()
}
func test_log() {
	logtest.Logtest.Test1()
	logtest.Logtest.Test2()
	logtest.Logtest.Test3()
	logtest.Logtest.Test4()
}
func test_type() {
	typeconvertest.TypeConvtest.Test1()
	typeconvertest.TypeConvtest.Test2()
	typeconvertest.TypeConvtest.Test3()
	typeconvertest.TypeConvtest.Test4()
	typeconvertest.TypeConvtest.Test5()
	typeconvertest.TypeConvtest.Test6()
	typeconvertest.TypeConvtest.Test7()
	typeconvertest.TypeConvtest.Test8()
	typeconvertest.TypeConvtest.Test9()
	typeconvertest.TypeConvtest.Test10()
}
func test_datavalidation() {
	datavalidation.DataValidationtest.Test1()
	datavalidation.DataValidationtest.Test2()
	datavalidation.DataValidationtest.Test3()
	datavalidation.DataValidationtest.Test4()
	datavalidation.DataValidationtest.Test5()
	datavalidation.DataValidationtest.Test6()
	datavalidation.DataValidationtest.Test7()
	datavalidation.DataValidationtest.Test8()
	datavalidation.DataValidationtest.Test9()
}
func test_cache() {
	cachetest.Cachetest.Test1()
	cachetest.Cachetest.Test2()
	cachetest.Cachetest.Test3("xxx")
}
func test_trace() {
	tracetest.Tracetest.Test1()
	gcron.AddSingleton("* * * * * *", func() {
		tracetest.Tracetest.Test2()
		time.Sleep(2 * time.Second)
		itime++
		if itime >= 3 {
			gcron.Stop("test")
		}
	}, "test")

}

func test_trace2() {
	tracetest.Tracetest2.Test1()
	//time.Sleep(1*time.Second)
	gcron.AddSingleton("* * * * * *", func() {
		tracetest.Tracetest2.Test2()
		time.Sleep(2 * time.Second)
		itime++
		if itime >= 3 {
			gcron.Stop("test2")
		}
	}, "test2")
}

var (
	config = gredis.Config{
		Host: "127.0.0.1",
		Port: 16380,
		Db:   0,
		Pass: "yanfa123!",
	}
)

func main() {
	itime = 0
	//g.SetDebug(true)
	s := g.Server()
	//s.SetIndexFolder(true)
	//s.SetServerRoot("./public/html")
	//s.AddSearchPath("./public")
	//s.Group("/", func(group *ghttp.RouterGroup) {
	//group.GET("/template", func(r *ghttp.Request) {
	//	r.Response.WriteTplDefault(g.Map{
	//		"name": "GoFrame",
	//	})
	//})
	//})
	/*s.BindHandler("/template", func(r *ghttp.Request) {
		r.Response.WriteTpl("testtemplate1.tpl", g.Map{
			"id":   123,
			"name": "xxx",
		})
	})
	v := g.View()
	v.SetDelimiters("{{", "}}")
	v.SetPath("template")
	s.BindHandler("/template2", func(r *ghttp.Request) {
		tplContent := `id:{{.id}},name:{{.name}}`
		r.Response.WriteTplContent(tplContent, g.Map{
			"id":   123,
			"name": "xxx",
		})
	})*/
	//test_err()
	//test_log()
	//test_type()
	//test_datavalidation()
	//test_cache()
	//g.Redis()
	//test_trace()
	test_trace2()
	// gcfg.Instance().SetFileName("config.toml")
	group := "test"
	gredis.SetConfig(&config, group)
	gredis.Instance(group).DoVar("SET", "k", "v")
	rr, _ := gredis.Instance(group).DoVar("GET", "k")
	fmt.Println(rr.String())
	s.Run()
	//g.Server().Run()
}
